﻿var app = angular.module('stuApp', ['ngResource', 'ngCookies']);
app.config(['$locationProvider', function ($locationProvider) {
    $locationProvider.html5Mode({
        enabled: true,
        requireBase: false
    });
}]);
app.controller('parseCtr', function ($scope, parseService, $cookieStore, $location) {
    $scope.topicList = [];
    $scope.saveinfo = {
        "student_id":"",
        "xt_exercises_id":"",
        "reason_id":"",
        "reason_text": "",
    }
    //错在哪
    $scope.set_reason_text = function (outindex) {
        $scope.saveinfo = {
            "student_id": $cookieStore.get('loginInfo').empid,
            "xt_exercises_id": $scope.topicList[outindex].exercises_id,
            "reason_id": "0",
            "reason_text": $scope.topicList[outindex].reason_text,
        }
        $scope.save();
    }
    //选择主观原因
    $scope.reasonChosen = function (outindex, index) {
        if ($scope.topicList[outindex].xt_exercises_reason[index].ischosen == null) {
            $scope.topicList[outindex].xt_exercises_reason[index].ischosen = true;
        } else {
            $scope.topicList[outindex].xt_exercises_reason[index].ischosen = !$scope.topicList[outindex].xt_exercises_reason[index].ischosen;
        }
        $scope.saveinfo = {
            "student_id": $cookieStore.get('loginInfo').empid,
            "xt_exercises_id": $scope.topicList[outindex].exercises_id,
            "reason_id": $scope.topicList[outindex].xt_exercises_reason[index].id,
            "reason_text": $scope.topicList[outindex].reason_text,
        }
        if ($scope.topicList[outindex].xt_exercises_reason[index].ischosen == true) {
            $scope.save();
        }
        else if ($scope.topicList[outindex].xt_exercises_reason[index].ischosen == false) {
            $scope.del();
        }
    }
    //插入错题信息
    $scope.save = function () {
        if ($scope.saveinfo.reason_text == null || $scope.saveinfo.reason_text.length <= 0) {
            $scope.saveinfo.reason_text = "";
        }
        parseService.Setstu_reason($scope.saveinfo, function (data) {
            if (data) {

            }
        })
    }
    //删除错题信息
    $scope.del = function () {
        if ($scope.saveinfo.reason_text == null || $scope.saveinfo.reason_text.length <= 0) {
            $scope.saveinfo.reason_text = "";
        }
        parseService.Delstu_reason($scope.saveinfo, function (data) {
            if (data) {

            }
        })
    }
    //数据
    $scope.do_search = function () {
        var par = {
            "student_id": $cookieStore.get('loginInfo').empid,
            "chapter_id": $location.search().chapter_id
        }
        parseService.getParseList(par, function (data) {
            $scope.topicList = data.data;
        })
    }
    //加载
    $scope.init = function () {
        $scope.do_search();
    }
    $scope.init();
})